//package com.js.mvpdemo.ui.first;
//
//import android.os.Bundle;
//import android.view.View;
//import android.widget.TextView;
//
//import androidx.annotation.NonNull;
//import androidx.appcompat.widget.Toolbar;
//import androidx.recyclerview.widget.LinearLayoutManager;
//import androidx.recyclerview.widget.RecyclerView;
//
//import com.baidu.mapapi.model.LatLng;
//import com.chad.library.adapter.base.BaseQuickAdapter;
//import com.js.fzxj.BaseApplication;
//import com.js.fzxj.R;
//import com.js.fzxj.adapter.MissionDetailAdapter;
//import com.js.fzxj.ui.first.work.SignInFragment;
//import com.js.fzxj.ui.first.work.UploadPhotoAndDataFragment;
//import com.js.fzxj.ui.first.work.UploadPhotoFragment;
//import com.js.lib_common.base.MvpFragment;
//import com.js.lib_common.event.StartBrotherEvent;
//import com.js.lib_common.mvp.model.response.MissionDetailResponse;
//import com.js.lib_common.mvp.model.response.MissionResponse;
//import com.js.lib_common.mvp.presenter.MissionDetailPresenter;
//import com.js.lib_common.mvp.view.MissionDetailView;
//import com.lxj.xpopup.XPopup;
//import com.lxj.xpopup.core.BasePopupView;
//import com.lxj.xpopup.interfaces.OnConfirmListener;
//import com.scwang.smartrefresh.layout.SmartRefreshLayout;
//import com.scwang.smartrefresh.layout.api.RefreshLayout;
//import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
//
//import org.greenrobot.eventbus.EventBus;
//
//import java.util.List;
//
//import butterknife.BindView;
//
//
//public class MissionDetailFragment extends MvpFragment<MissionDetailPresenter> implements MissionDetailView {
//
//
//    @BindView(R.id.toolbar_title)
//    TextView toolbarTitle;
//    @BindView(R.id.toolbar)
//    Toolbar toolbar;
//    @BindView(R.id.rcy_list)
//    RecyclerView mRecyclerView;
//    @BindView(R.id.refreshLayout)
//    SmartRefreshLayout refreshLayout;
//    private MissionDetailAdapter mAdapter;
//    private MissionResponse response;
//    private static final String ARG_BEAN = "response";
//
//    public static MissionDetailFragment newInstance(MissionResponse response) {
//        Bundle args = new Bundle();
//        MissionDetailFragment fragment = new MissionDetailFragment();
//        args.putSerializable(ARG_BEAN, response);
//        fragment.setArguments(args);
//        return fragment;
//    }
//
//
//    @Override
//    protected int getLayoutId() {
//        return R.layout.fragment_tab_first_mission_detail;
//    }
//
//
//    @Override
//    public void onSupportVisible() {
//        super.onSupportVisible();
//        refreshLayout.autoRefresh();
//    }
//
//    @Override
//    protected void initView() {
//        toolbarTitle.setText("任务详情");
//        Bundle bundle = getArguments();
//        if (bundle != null) {
//            response = (MissionResponse) bundle.getSerializable(ARG_BEAN);
//            if (response != null)
//                toolbarTitle.setText(response.getTaskName());
//        }
//        initToolbarNav(toolbar);
//
//        initSmartRefreshLayout(refreshLayout);
//        refreshLayout.setEnableLoadMore(false);
//        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
//            @Override
//            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
//                mAdapter.getData().clear();
//                mAdapter.notifyDataSetChanged();
//                mvpPresenter.loadData(response.getId());
//            }
//        });
//
//
//        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
//        mAdapter = new MissionDetailAdapter(_mActivity, null);
//        mRecyclerView.setAdapter(mAdapter);
//
//        mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
//            @Override
//            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
//                switch (view.getId()) {
//                    case R.id.btn_submit:
//                        MissionDetailResponse response = (MissionDetailResponse) adapter.getItem(position);
//                        if (response == null)
//                            return;
////                        if (response.getLogTypeName().contains("接单")) {
////                            initDialog(response);
////                        } else if (response.getLogTypeName().contains("就位")) {
////                            EventBus.getDefault().post(new StartBrotherEvent(SignInFragment.newInstance(response)));
////
////                        } else if (response.getLogTypeName().contains("关闭阀门")) {
////
////                        } else if (response.getLogTypeName().contains("开启阀门")) {
////
////                        } else if (response.getLogTypeName().contains("施工启动")) {
////                            //                            EventBus.getDefault().post(new StartBrotherEvent(SignInFragment.newInstance(response)));
////                        }
//                        //
//
//                        switch (response.getLogType()) {
//                            case 2://接单
//                                initDialog(response);
//                                break;
//                            case 3://就位
//                                EventBus.getDefault().post(new StartBrotherEvent(SignInFragment.newInstance(response)));
//                                break;
//                            case 12://施工-砌挡墙
//                            case 13://施工-盖天窗
//                            case 14://施工-防腐
//
//                            case 22://施工-切割旧管
//                            case 23://施工-检漏合格
//
//                            case 31://关阀
//                            case 33://开阀
//                                EventBus.getDefault().post(new StartBrotherEvent(UploadPhotoFragment.newInstance(response)));
//
//
//                                break;
//                            case 41://降压放散
//                                EventBus.getDefault().post(new StartBrotherEvent(UploadPhotoAndDataFragment.newInstance(response)));
//
//                                break;
//                        }
//
//                        break;
//                }
//            }
//        });
//
//
//    }
//
//
//    @Override
//    protected MissionDetailPresenter createPresenter() {
//        return new MissionDetailPresenter(this);
//    }
//
//
//    @Override
//    public void onFailed(String message) {
//        refreshLayout.finishRefresh(false);//结束刷新（刷新失败）
//        refreshLayout.finishLoadMore(false);//结束加载（加载失败）
//        toastShow(message);
//    }
//
//    @Override
//    public void onError(String message) {
//        refreshLayout.finishRefresh(false);//结束刷新（刷新失败）
//        refreshLayout.finishLoadMore(false);//结束加载（加载失败）
//        toastShow(message);
//    }
//
//
//    @Override
//    public void showMissionDetail(List<MissionDetailResponse> data) {
//        //        Collections.sort(data);//
//        for (int i = 0; i < data.size(); i++) {
//            MissionDetailResponse datum = data.get(i);
//            datum.setMissionResponse(response);
//            if (i == data.size() - 1) {
//                datum.setLast(true);
//            } else {
//                datum.setLast(false);
//            }
//            mAdapter.addData(datum);
//
//            mAdapter.notifyDataSetChanged();
//
//
//        }
//
//
//        refreshLayout.finishLoadMore();//结束加载
//        refreshLayout.finishRefresh();//结束刷新
//    }
//
//    @Override
//    public void onSuccess() {
//        refreshLayout.autoRefresh();
//        BasePopupView popupView = new XPopup.Builder(_mActivity)
//                .asConfirm("成功", "已经成功接单",
//                        "取消", "确定",
//                        null, null, true);
//        popupView.show();
//    }
//
//
//    private void initDialog(MissionDetailResponse response) {
//        BasePopupView popupView = new XPopup.Builder(_mActivity)
//                .asConfirm("接收任务", "是否接收任务安排？",
//                        "取消", "确定",
//                        new OnConfirmListener() {
//                            @Override
//                            public void onConfirm() {
//                                LatLng latLng = BaseApplication.getmLatLng();
//                                mvpPresenter.updataOrderInfo(response.getOrderId(), response.getLogType()+"", response.getId()
//                                        , latLng.latitude + "", latLng.longitude + "");
//
//                            }
//                        }, null, false);
//        popupView.show();
//    }
//
//
//}